<?php


namespace App\Model;


use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\URL;

/**
 * App\Model\Category
 *
 * @property int $id
 * @property string $name 分类名
 * @property int $sort 排序值
 * @property int $is_show 是否显示
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @property string|null $deleted_at
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Category whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Category whereDeletedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Category whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Category whereIsShow($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Category whereName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Category whereSort($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Category whereUpdatedAt($value)
 * @property string|null $thumb
 * @method static bool|null forceDelete()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Category newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Category newQuery()
 * @method static \Illuminate\Database\Query\Builder|\App\Model\Category onlyTrashed()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Category query()
 * @method static bool|null restore()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Category whereThumb($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Model\Category withTrashed()
 * @method static \Illuminate\Database\Query\Builder|\App\Model\Category withoutTrashed()
 * @mixin \Eloquent
 */
class Category extends Model
{

    use SoftDeletes;

    const SHOW_TRUE = 1;
    const SHOW_FALSE = 0;

    protected $table = 'category';

    public function getThumbUrl()
    {
        return URL::asset('/uploads/' . $this->thumb);
    }

    /**
     * 获取所有分类
     * @author thanatos thanatos915@163.com
     */
    public static function getAllCategories()
    {
        return static::where('is_show', static::SHOW_TRUE)->orderBy('sort', 'desc')->get();
    }

}
